package com.ymatou.iapi.sellercs.testcase;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.sellercs.parameter.AddCategoryBean;
import com.ymatou.iapi.sellercs.service.AddCategoryCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.database.sqlwapper.YmtSellerCSIMWapper;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.TestDataManager;
/**
*添加话术分类
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_AddCategory{
	private static AddCategoryBean addcategoryBean;
	private static AddCategoryCall addcategoryCall;
	private static int sellerId = Integer.parseInt(EnvSetup.getData("autotest_seller1"));
	private static int zsellerId = Integer.parseInt(EnvSetup.getData("autotest_seller_z"));
	private static YmtSellerCSIMWapper YmtSellerCSIMWapper;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("添加话术分类");
	}

	@Before
	public void caseUp() {
		addcategoryBean=new AddCategoryBean();
		addcategoryCall=new AddCategoryCall();
		YmtSellerCSIMWapper=new YmtSellerCSIMWapper();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(addcategoryCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_AddCategory_001() {
		Logger.start(true,"添加话术分类成功");
		try {
			addcategoryBean.setCSId(sellerId);
			addcategoryBean.setTitle("话术类别"+TestDataManager.getRandomNumToHex(5));
			addcategoryBean.setSort(1);
			addcategoryCall.setData(addcategoryBean);
			addcategoryCall.callService();			
			Logger.verifyIsContains("200", addcategoryCall.getString("Status"), "验证Status");	
			Logger.verifyEquals(true, addcategoryCall.getJsonObject().get("Result").getAsJsonObject().get("Success").getAsBoolean(), "验证Success");	
			List<Map>lm=YmtSellerCSIMWapper.selectIndividualdiscourseByCsid(addcategoryBean.getCSId());
			Logger.debug(lm);
			lm=lm.stream().filter(m->{
				return m.get("icTitle").equals(addcategoryBean.getTitle());
			}).collect(Collectors.toList());
			Logger.verifyEquals(true, lm.size()>=1, "验证有新增话术分类");
			Logger.verifyEquals(addcategoryBean.getCSId(),lm.get(0).get("CSId"), "验证csid");
			Logger.verifyEquals(addcategoryBean.getSort(),lm.get(0).get("icSort"), "验证icSort");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_AddCategory_002() {
		Logger.start(true,"不输入csid失败");
		try {
//			addcategoryBean.setCSId(sellerId);
			addcategoryBean.setTitle("话术类别"+TestDataManager.getRandomNumToHex(5));
			addcategoryBean.setSort(1);
			addcategoryCall.setData(addcategoryBean);
			addcategoryCall.callService();			
			Logger.verifyIsContains("400", addcategoryCall.getString("Status"), "验证Status");	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_AddCategory_003() {
		Logger.start(true,"不输入Title失败");
		try {
			addcategoryBean.setCSId(sellerId);
//			addcategoryBean.setTitle("话术类别"+TestDataManager.getRandomNumToHex(5));
			addcategoryBean.setSort(1);
			addcategoryCall.setData(addcategoryBean);
			addcategoryCall.callService();			
			Logger.verifyIsContains("400", addcategoryCall.getString("Status"), "验证Status");	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_AddCategory_004() {
		Logger.start(true,"子客服添加话术分类成功");
		try {
			addcategoryBean.setCSId(zsellerId);
			addcategoryBean.setTitle("话术类别"+TestDataManager.getRandomNumToHex(5));
			addcategoryBean.setSort(1);
			addcategoryCall.setData(addcategoryBean);
			addcategoryCall.callService();			
			Logger.verifyIsContains("200", addcategoryCall.getString("Status"), "验证Status");	
			Logger.verifyEquals(true, addcategoryCall.getJsonObject().get("Result").getAsJsonObject().get("Success").getAsBoolean(), "验证Success");	
			List<Map>lm=YmtSellerCSIMWapper.selectIndividualdiscourseByCsid(addcategoryBean.getCSId());
			lm=lm.stream().filter(m->{
				return m.get("icTitle").equals(addcategoryBean.getTitle());
			}).collect(Collectors.toList());
			Logger.verifyEquals(true, lm.size()>=1, "验证有新增话术分类");
			Logger.verifyEquals(addcategoryBean.getCSId(),lm.get(0).get("CSId"), "验证csid");
			Logger.verifyEquals(addcategoryBean.getSort(),lm.get(0).get("icSort"), "验证icSort");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}